void setMotor(int dirpin1,int dirpin2,int speedpin, int speed)
{
  if (speed == 0)
  {
    digitalWrite(dirpin1, LOW);
    digitalWrite(dirpin2, LOW);
    analogWrite(speedpin, 0);
  }
  else if (speed > 0)
  {
    digitalWrite(dirpin2, HIGH);
    digitalWrite(dirpin1, LOW);
    analogWrite(speedpin, speed);
  }
  else
  {
    digitalWrite(dirpin2, LOW);
    digitalWrite(dirpin1, HIGH);
    analogWrite(speedpin, -speed);
  }
}

boolean sci_digitalRead(uint8_t pin) {
  pinMode(pin, INPUT);
  boolean _return =  digitalRead(pin);
  pinMode(pin, OUTPUT);
  return _return;
}

void setup(){
  pinMode(PB9, OUTPUT);
  pinMode(PB8, OUTPUT);
  digitalWrite(PB9, LOW);
  digitalWrite(PB8, LOW);
  pinMode(PB0, OUTPUT);
}

void loop(){
  do{
    setMotor(PB9, PB8, PA0, -255);
    digitalWrite(PB0,LOW);
  }while(!(sci_digitalRead(PA15)));
  do{
    setMotor(PB9, PB8, PA0, 255);
    digitalWrite(PB0,HIGH);
  }while(sci_digitalRead(PA15));

}
